package com.wang.code;

import java.util.Comparator;
import java.util.TreeSet;
public class _8TreeSetTest2 {

	public static void main(String[] args) {
		UserComparator comparator = new UserComparator();
		TreeSet set = new TreeSet(new Comparator<User>() {

			@Override
			public int compare(User o1, User o2) {
				return 0;
			}
		});
		System.out.println("=====================");
		
		System.out.println("===================");
		Student1 stu1 = new Student1("a",12);
		Student1 stu2 = new Student1("a",12);
		Student1 stu8 = new Student1("a",12);
		Student1 stu3 = new Student1("bnm",43);
		Student1 stu4 = new Student1("bnm",123);
		
		Student1 stu5 = new Student1("qwe",34);
		Student1 stu6 = new Student1("qwe2",123);
		Student1 stu7 = new Student1("qweddd",255);
		set.add(stu1);
		set.add(stu2);
		set.add(stu3);
		set.add(stu4);
		set.add(stu5);
		set.add(stu6);
		set.add(stu7);
		set.add(stu8);
		System.out.println(set);
		
	}

}

class User implements Comparable<User>{
	private String name;
	private double height;
	public User() {
	}
	public User(String name, double height) {
		super();
		this.name = name;
		this.height = height;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getHeight() {
		return height;
	}
	public void setHeight(double height) {
		this.height = height;
	}
	@Override
	public String toString() {
		return "[" + name + ", " + height + "]";
	}
	@Override
	public int compareTo(User o) {
		if (this.name.length() > o.name.length()) {
			return 1;
		} else if (this.name.length() < o.name.length()){
			return -1;
		} else {
			if (this.height > o.height) {
				return 1;
			} else if (this.height < o.height){
				return -1;
			} else {
				return 0;
			}
		}
	}
	
}
